<?php

namespace catchAdmin\phone\model;

use catchAdmin\model\SysLabel;

class SysLabelUser extends \catchAdmin\model\SysLabelUser
{


    public function saveData($param)
    {
        $this->startTrans();

        $arr_save = [];
        foreach ($param['label'] as $k => $v) {
            $arr_save[] = $v;
        }

        $this
            ->where('wechat_user_id', $this->getLoginId())
            ->whereNotIn('sys_label_id', $arr_save)
            ->where('deleted_at', 0)
            ->update([
                'deleted_at' => time(),
            ]);

        foreach ($param['label'] as $k => $v) {
            if ($this
                    ->where('wechat_user_id', $this->getLoginId())
                    ->where('sys_label_id', $v)
                    ->count() > 0) {
                continue;
            }

            $this->saveDataCC([
                'wechat_user_id' => $this->getLoginId(),
                'sys_label_id'   => $v,
            ]);
        }

        (new \catchAdmin\model\UserCompany())
            ->where('wechat_user_id', $this->getLoginId())
            ->update([
                'sys_label_name' => (new SysLabel())->getLabelNameStr($param['label']),
            ]);

        $this->commit();

        return 1;
    }

    ######################################## 显示 ################################################

}
